from rest_framework.generics import ListAPIView,CreateAPIView
from meiduo_admin.my_paginate import MyPageNumberPagination
from users.models import User
from . import user_serializers


class UserView(ListAPIView,CreateAPIView):
    pagination_class = MyPageNumberPagination
    serializer_class = user_serializers.UserSerializer
    queryset = User.objects.all()

    def get_queryset(self):
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return User.objects.filter(username__contains=keyword).order_by("id").all()
        else:
            return User.objects.order_by("id").all()